﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Iguana.Core.HypterText.Attributes
{
    internal static class UtilAttributes
    {
        internal static string SetAttribute(IAttribute attribute, string newValue)
        {
            // This means that the Attribute has a specific list of acceptable values.
            if (attribute.PreDefinedValues)
            {
                if (attribute.AcceptableValues.Contains(newValue))
                {
                    return newValue;
                }
                else
                {
                    if (String.IsNullOrEmpty(newValue))
                    {
                        return newValue;
                    }
                    else
                    {
                        throw new InvalidValueException(String.Format(SR.SR_EXC_NOTACCEPTABLE, newValue, attribute.Name));
                    }
                }
            }
            else
            {
                // TODO: Add some validation here later in the future.
                return newValue;
            }
        }
    }
}
